<extend name="Layout/ins_popup" />
<block name="content">
    {:W('PageHeader/popup',array('name'=>'编辑'))}
	<div class="row">
		<div class="col-sm-4 sub_left_menu">
			<div class="well">
				<?php echo $menu ?>
			</div>
		</div>
		<div class="col-sm-8" >
            <link href="__INS__/iCheck/skins/square/blue.css" rel="stylesheet">
			<div class="ul_table border-bottom user_list ul_table-responsive"  >
				<ul>
					<li class="thead">
						<div class="pull-left">
							<span class="col-8 hidden-xs" >员工编码</span>
							<span class="col-8" >姓名</span>
							<span class="col-8">职位</span>
							<span class="col-6 hidden" >职级</span>
							<span class="col-10" >手机</span>

						</div>
						<div class="pull-left  hidden-xs col-10">
							<span style="width:100%;">邮件</span>
						</div>
                        <div class="pull-right hidden-xs col-3" style="margin-right: 20px;">
                        <span style="width:100%;">选择</span>
                        </div>

					</li>
				</ul>
			</div>

		</div>
	</div>
	<div id="sample" class="hidden">
		<li class="tbody">
			<div class="pull-left">
				<span class="col-8 emp_no hidden-xs" ></span>
				<span class="col-8 name" ></span>
				<span class="col-8 position" ></span>
				<span class="col-6 rank hidden-xs hidden" ></span>
				<span class="col-10 mobile_tel"></span>

			</div>
			<div class="pull-left col-10 hidden-xs">
				<span style="width:100%;" class="email">邮件</span>
			</div>
            <div class="pull-right  hidden-xs col-3" style="margin-right: 20px;">
                     <span style="width:100%;" class="select"></span>
            </div>


		</li>
	</div>
</block>
<block name="js">
    <script src="__INS__/iCheck/jquery.icheck.min.js"></script>
	<script type="text/javascript">
        var notifyArray = new Object();
        var notifyFlag = new Array();
        $(".page-header .btn-primary").text("发送");
		function showdata(result) {
			$(".user_list li.tbody").remove();
			for (var s in result.data) {
				$("#sample .emp_no").text(result.data[s].emp_no);
				$("#sample .name").text(result.data[s].name);
				$("#sample .position").text(result.data[s].position_name);
				$("#sample .rank").text(result.data[s].rank_name);
				$("#sample .email").text(result.data[s].email);
                if(notifyArray[result.data[s].emp_no]){
                    $("#sample .select").html("<input type='checkbox' id='"+result.data[s].emp_no+"' checked>");
                }else{
                    $("#sample .select").html("<input type='checkbox' id='"+result.data[s].emp_no+"'>");
                }

				$mobile = $("<a></a>");
				$mobile.attr("href", "tel:" + result.data[s].mobile_tel);
				$mobile.html(result.data[s].mobile_tel);

				$("#sample .mobile_tel").html($mobile);

				$("#sample li").attr("email", result.data[s].email);
				$("#sample li").attr("duty", result.data[s].duty);
				$("#sample li").attr("name", result.data[s].name);
				$("#sample li").attr("office_tel", result.data[s].office_tel);
				$("#sample li").attr("mobile_tel", result.data[s].mobile_tel);
				$("#sample li").attr("pic", result.data[s].pic);


				html = $("#sample").html();

				$(".user_list ul").append(html);

				$("#sample li span").text("");
			}

			if ($(".user_list li.tbody").length > 0) {
				$(".user_list li.tbody").get(0).click();
			}
		}




		$(document).ready(function() {

			$(".sub_left_menu .tree_menu a").click(function() {
				$(".sub_left_menu .tree_menu a").each(function() {
					$(this).attr("class", "");
				});
				$(this).attr("class", "active");
				sendAjax("{:U('read')}", "id=" + $(this).attr("node"), function(data) {
					showdata(data);
                    $("input").iCheck({

                        checkboxClass: 'icheckbox_square-blue',
                        increaseArea: '20%'
                    });

                    $("input").on(" ifChecked",function(event){
                      var emp_no = $(this).parents(".tbody").find(".emp_no").text();
                      var notify_emp_no = "{$Think.session.emp_no}";
                      var notify_content = "车牌号为{$carNum}的汽车还剩{$motDistance}天！";

                        notifyArray[$(this).attr("id")]={emp_no:emp_no,notify_emp_no:notify_emp_no,notify_content:notify_content};
                        notifyFlag.push(true);
                        console.log(notifyArray);
                    });

                    $("input").on("ifUnchecked",function(event){
                        delete notifyArray[$(this).attr("id")];
                        notifyFlag.pop();
                        console.log(notifyArray);
                    });

				});
				return false;
			});

            $(".page-header .btn-primary").click(function(){
                if(notifyFlag.length > 0){
                    $.post("{:U('sendNotify')}",
                        {'notifyList':notifyArray},
                        function(data){
                            ui_alert(data.info, function() {
                            // parent.location.reload(true);
                            myclose();
                        });
                    });
                }else{
                    ui_error("未选择通知对象！");
                }


            });



		});

	</script>
</block>